package osgi.common.services;

import java.io.File;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class LoggerHelper {

	
	protected static final String LOG4J_PROPERTIES = "C:/formosa/config/karaf/log4j.properties";
	protected static LoggerHelper instance = null;
	
	
	protected LoggerHelper() {
		super();
		
		if(new File(LOG4J_PROPERTIES).exists()){
			
		  PropertyConfigurator.configure(LOG4J_PROPERTIES);
		  
		} else {
			
		  BasicConfigurator.configure();
		  
		}
		
	}

	
	public static synchronized LoggerHelper getInstance(){
		
		if(instance == null){
			instance = new LoggerHelper();
		}
		
		return instance;
		
	}

	@SuppressWarnings("rawtypes")
	public Logger getLog4j (Class clazz) {		
		return Logger.getLogger(clazz);
	}
	
	
	@SuppressWarnings("rawtypes")
	public static Logger getLogger(Class clazz) {		
		return getInstance().getLog4j(clazz);
	}

	
	
	
	public Logger getLog4j (String loggerName) {		
		return Logger.getLogger(loggerName);
	}
	
		
	public static Logger getLogger(String loggerName) {		
		return getInstance().getLog4j(loggerName);
	}
	
	
}
